#include <functional>
#include <iostream>
using namespace std;
struct divide_struct {
  double a, b;
  double divide() { return a / b; };
};
int add(int a, int b) { return a + b; }
int main() {
  using namespace std::placeholders;
  auto five = std::bind(add, 2, 3);
  std::cout << "five:" << five() << "\n"; // 5
  // 绑定一个参数的时候不能直接绑定第二个
  auto add_two = std::bind(add, _1, 3);
  std::cout << add_two(3) << "\n"; // 6
  divide_struct ds{6, 2};
  // 绑定成员方法
  auto double_three = std::bind(&divide_struct::divide, _1); // divide()
  std::cout << "three " << double_three(ds) << "\n";         // 2
  // 绑定成员变量
  auto divide_two = std::bind(&divide_struct::a, _1);
  std::cout << divide_two(ds, 12) << "\n";          // 6,a=12
  auto divide_a = std::bind(&divide_struct::a, ds); //获取ds::a
  std::cout << divide_a();
}
